const express = require('express');
const router = express.Router();
const bodyParser = require('body-parser');
const managerSQL = require('../../db/managerSQL');
const data = require('../data');
const loginSQL = require('../../db/loginSQL')

router.post('/getuser', bodyParser.json(), (req, res) => {
    // 检查用户ID是否为空
    if (!req.body["userID"]
        || typeof req.body["userID"] != "number") {
        res.json({
            err: 1,
            message: '用户ID为空'
        })
    }
    // 下方改数据库操作代码
    else {
        let userID = req.body["userID"];

        loginSQL.getByID(userID, (result) => {
            var userStatus = result[0].userStatus;
            var userPower = result[0].userPower;
            //判断管理员权限
            if (userPower == 0) {
                res.json({
                    err: 2,
                    message: '权限不足',
                    userPower: 0
                })
            } else if (userStatus == 0) {
                res.json({
                    err: 3,
                    message: '用户被封禁'
                })
            } else {
                managerSQL.getUserList(userID, (userList) => {
                    res.json({
                        err: 200,
                        message: '成功获取用户列表',
                        userList
                    })
                })
            }
        })
    }
})

module.exports = router;